package com.aisino.inveli.vinda.utils;

import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import javafx.stage.Window;

import java.util.Optional;

/**
 * @author leifeng
 * @Date 2017-11-14
 * 弹框工具类
 **/
public class AlertUtil {
    /**
     * 弹出提示框
     * @param contentText
     * @param title
     * @param window
     */
    public static void showInfoAlert(String contentText, String title, Window window) {
        Alert alert = new Alert(Alert.AlertType.INFORMATION,contentText);
        alert.setTitle("提示");
        alert.setHeaderText(title);
        alert.initOwner(window);
        alert.show();
    }

    /**
     * 弹出错误提示框
     * @param contentText
     * @param window
     * @param title
     */
    public static void showErrAlert(String contentText, Window window, String title) {
        Alert alert = new Alert(Alert.AlertType.ERROR,contentText);
        alert.setTitle("错误");
        alert.setHeaderText(title);
        alert.initOwner(window);
        alert.show();
    }

    /**
     * 弹出确认提示框
     * @param title
     * @param window
     * @param contentText
     * @return
     */
    public static Boolean confirmAlert(String title,Window window, String contentText) {
        Alert alert = new Alert(Alert.AlertType.CONFIRMATION,contentText,new ButtonType("取消", ButtonBar.ButtonData.NO),
                new ButtonType("确定", ButtonBar.ButtonData.YES));
        alert.setTitle("确认");
        alert.setHeaderText(title);
        alert.initOwner(window);
        Optional<ButtonType> type = alert.showAndWait();
        //根据点击结果返回
        if(type.get().getButtonData().equals(ButtonBar.ButtonData.YES)){
            return true;
        } else {
            return false;
        }
    }
}
